<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//视频详情表
class Video_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->video = 'video';
        $this->video_comment = 'video_comment';
        $this->video_like = 'video_like';
        $this->video_favorite = 'video_favorite';
    }
    //获取视频点赞单个用户记录状态
    function get_video_like_info($where){
        $this->db->select('*');
        $this->db->from($this->video_like);
        $this->db->where($where);
        return $this->db->get()->row_array();
    }
    //获取视频点赞单个用户记录状态
    function get_video_like_status($where){
        $this->db->select('status');
        $this->db->from($this->video_like);
        $this->db->where($where);
        return $this->db->get()->num_rows();
    }
    //获取视频收藏单个用户记录状态
    function get_video_favorite_status($where){
        $this->db->select('*');
        $this->db->from($this->video_favorite);
        $this->db->where($where);
        return $this->db->get()->num_rows();
    }
    
    //增加视频点击赞的数量
    function insert_video_like($data){
        $this->db->insert($this->video_like,$data);
        if($this->db->affected_rows()==1){
           $this->db->set('likes','likes+1',FALSE);
           $this->db->where('id',$data['video_id']);
           $this->db->update($this->video);
        }
        return $this->db->affected_rows();
    }

    function insert_video_hates($data){
        $this->db->insert($this->video_like,$data);
        if($this->db->affected_rows()==1){
            $this->db->set('hates','hates+1',FALSE);
            $this->db->where('id',$data['video_id']);
            $this->db->update($this->video);
        }
        return $this->db->affected_rows();
    }



}
